﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Automobile.service.Common;
using Automobile.service.Model;
using System.Data.SqlClient;
using System.Data;

namespace Automobile.service.DAL
{
    public class ShipmentsDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 零售管理——添加
        /// </summary>
        /// <returns></returns>
        public int AddShioments(Shipments sp, string xml)
        {
            SqlParameter[] ship = {
                             new SqlParameter("@Shipblitems",sp.Shipments_blitems),
                             new SqlParameter("@ShipPer",sp.Shipments_Per),
                             new SqlParameter("@ShipPor",sp.Shipments_Por),
                             new SqlParameter("@ShipPeosor",sp.Shipments_Peosor),
                             new SqlParameter("@MemId",sp.MemberCard_Id),
                             new SqlParameter("@WarId",sp.WareHose_Id),
                             new SqlParameter("@ShipPrice",sp.Shipments_Price),
                             new SqlParameter("@ShipPricepor",sp.Shipments_Pricepor),
                             new SqlParameter("@ShipRemark",sp.Shipments_Remark),
                            new SqlParameter("@xml",xml)
                             };
            return helper.ExecNonquery_Proc("Proc_AddShioments", ship);
        }
        
        /// <summary>
        /// 零售管理——显示
        /// </summary>
        /// <returns></returns>
        public DataTable ShowShipMents()
        {
            return helper.ExecDataTable_Proc("Proc_ShowShipMents");
        }
        /// <summary>
        /// 零售管理——获取零售总行数
        /// </summary>
        /// <returns></returns>
        public int GetShipMentsCount()
        {
            string sql = "select count(Shipments_Id) from Shipments";
            return Convert.ToInt32(helper.ExecScalar(sql));
        }
        /// <summary>
        /// 零售管理——查看详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetShipMentsMatsByid(int id)
        {
            SqlParameter[] shipmentid = {
                                        new SqlParameter("@id",id)
                                        };
            return helper.ExecDataTable_Proc("Proc_GetShipMentsByid", shipmentid);
        }
        /// <summary>
        /// 零售管理——根据会员名称查询
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public DataTable GetShipMentsByName(string name)
        {
            name = '%' + name + '%';
            SqlParameter[] memname ={
                                       new SqlParameter("@MemberName",name)
                                   };
            return helper.ExecDataTable_Proc("Proc_GetShipMentsByName", memname);
        }
    }
}
